﻿
namespace Orid.Management.Statistics.Tools.Decomposition.Config
{
    using System;
    using System.Xml.Serialization;
    using System.IO;

    [Serializable]
   public  class Setting
    {
        static readonly string xmlFileName = AppDomain.CurrentDomain.BaseDirectory + "DecompositionSetting.xml";

        static private Setting setting ;

        public static Setting SettingInstance
        {
            get {
                if (setting == null)
                {
                 
                    GetSettingFromXmlFile();
                   
                    if (setting == null)
                    {
                        setting = new Setting();
                    }
                }
                return setting; 
            }
            set {
               
                setting = value; 
            }
        }

        private static   void GetSettingFromXmlFile()
        {

            FileInfo file = new FileInfo(xmlFileName);
            if (File.Exists(file.ToString()))
            {
                string xml = File.ReadAllText(file.FullName);
                
                if (!string.IsNullOrEmpty(xml))
                {
                    setting = Logic.SimpleSerializer.Deserialize(typeof(Setting), xml) as 
Setting;
                }
                
            }

            
        }

        public void SaveSettingToXmlFile()
        {
            string xml = Logic.SimpleSerializer.Serialize(setting);

            FileInfo file = new FileInfo(xmlFileName);
            if (File.Exists(file.ToString()))
            {
                file.Delete();                
            }
            File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "DecompositionSetting.xml", xml);
        }

        private Setting() { }
        
        [XmlElement("Matters_Offline")]
        public string Matters_Offline { get; set; }
        
        [XmlElement("OrderDatas_Offline")]
        public string OrderDatas_Offline { get; set; }

        [XmlElement("Distributes_Offline")]
        public string Distributes_Offline { get; set; }

        [XmlElement("Jobs_Offline")]
        public string Jobs_Offline { get; set; }

        [XmlElement("ParentDatas_Offline")]
        public string ParentDatas_Offline { get; set; }

        [XmlElement("ChildDatas_Offline")]
        public string ChildDatas_Offline{get; set; }

        [XmlElement("FutureManagement_Offline")]
        public string FutureManagement_Offline { get; set; }

        [XmlElement("DecompositionOrders_Offline")]
        public string DecompositionOrders_Offline { get; set; }

        [XmlElement("UploadJobStore_Offline")]
        public string UploadJobStore_Offline { get; set; }

        [XmlElement("OrderFlowProgress_Offline")]
        public string OrderFlowProgress_Offline { get; set; }

        [XmlElement("DataStore_Offline")]
        public string DataStore_Offline { get; set; }

        //Joblogs table 
        //Add @  2010-07-09
        string jobLogs_Offline = string.Empty;
        [XmlElement("JobLogs_Offline")]
        [System.Configuration.DefaultSettingValueAttribute("")]
        public string JobLogs_Offline
        {
            get { return jobLogs_Offline; }
            set { jobLogs_Offline = value; }
        }

        //RoleJobLevels
        //Add @  2010-07-19
        string roleJobLevels_Offline = string.Empty;

        [XmlElement("RoleJobLevels_Offline")]
        [System.Configuration.DefaultSettingValueAttribute("")]
        public string RoleJobLevels_Offline
        {
            get { return roleJobLevels_Offline; }
            set { roleJobLevels_Offline = value; }
        }

        //AccountInRole_Offline
        //Add @  2010-07-19
        string accountInRole_Offline = string.Empty;
        [XmlElement("AccountInRole_Offline")]
        [System.Configuration.DefaultSettingValueAttribute("")]
        public string AccountInRole_Offline
        {
            get { return accountInRole_Offline; }
            set { accountInRole_Offline = value; }
        }


        string accounts_Offline;

        [XmlElement("Accounts_Offline")]
        public string Accounts_Offline
        {
            get
            {
                return accounts_Offline;
            }
            set
            {
                accounts_Offline = value;
            }
        }


        /////////////////////////////////////
        
        string offline;

        [XmlElement("Offline")]
        [System.Configuration.DefaultSettingValueAttribute("False")]
        public string Offline
        {
            get
            {
                return offline;
            }
            set
            {
                offline = value;
            }
        }

        string decompositionDBTimeOut = string.Empty;

        [XmlElement("DecompositionDBTimeOut")]
        [System.Configuration.DefaultSettingValueAttribute("3000")]
        public string DecompositionDBTimeOut
        {
            get { return decompositionDBTimeOut; }
            set { decompositionDBTimeOut = value; }
        }

        string serverName = string.Empty;

        [XmlElement("ServerName")]
        [System.Configuration.DefaultSettingValueAttribute("")]
        public string  ServerName
        {
            get { return serverName; }
            set { serverName = value; }
        }

        string autoInterval;
        [XmlElement("AutoInterval")]
        [System.Configuration.DefaultSettingValueAttribute("60000")]
        public string AutoInterval
        {
            get { return autoInterval; }
            set { autoInterval = value; }
        }

        string threadNumber;
        [XmlElement("ThreadNumber")]
        [System.Configuration.DefaultSettingValueAttribute("1")]
        public string ThreadNumber
        {
            get { return threadNumber; }
            set { threadNumber = value; }
        }

        string dBAddress_Online;
        [XmlElement("DBAddress_Online")]
        public string DBAddress_Online
        {
            get
            {
                return dBAddress_Online;
            }
            set
            {
                dBAddress_Online = value;
            }
        }

        string ddAddress_Offline;

        [XmlElement("DBAddress_Offline")]
        [System.Configuration.DefaultSettingValueAttribute("")]
        public string DBAddress_Offline
        {
            get
            {
                return ddAddress_Offline;
            }
            set
            {
                ddAddress_Offline = value;
            }
        }

        string dBAddress_Decomposition;

        [XmlElement("DBAddress_Decomposition")]
        public string DBAddress_Decomposition
        {
            get
            {
                return dBAddress_Decomposition;
            }
            set
            {
                dBAddress_Decomposition = value;
            }
        }

        string decompositionOrders_Online;

        [XmlElement("DecompositionOrders_Online")]
        public string DecompositionOrders_Online
        {
            get
            {
               return decompositionOrders_Online;
            }
            set
            {
                decompositionOrders_Online = value;
            }
        }


        private string dropOrderFlag;
        [XmlElement("DropOrderFlag")]
        [System.Configuration.DefaultSettingValueAttribute("True")]
        public string DropOrderFlag 
        {
            get
            {
                if (String.IsNullOrEmpty(dropOrderFlag))
                {
                    dropOrderFlag ="False";
                }

                return dropOrderFlag;
            }  
            set {  dropOrderFlag = value; }
        }
         
        public string this[string propertyName]
        {
            get
            {
                return (GetProperty(propertyName));
            }
            set
            {
                SetProperty(propertyName,value);
            }
        }

        private void SetProperty(string propertyName,string Value)
        {
            switch (propertyName)
            {
                case "Matters_Offline":
                    setting.Matters_Offline = Value;
                    break;
                case "OrderDatas_Offline":
                    setting.OrderDatas_Offline = Value;
                    break;
                case "Distributes_Offline":
                    setting.Distributes_Offline = Value;
                    break;
                case "Jobs_Offline":
                    setting.Jobs_Offline = Value;
                    break;
                case "ParentDatas_Offline":
                    setting.ParentDatas_Offline = Value;
                    break;
                case "ChildDatas_Offline":
                    setting.ChildDatas_Offline = Value;
                    break;
                case "FutureManagement_Offline":
                    setting.FutureManagement_Offline = Value;
                    break;
                case "DecompositionOrders_Offline":
                    setting.DecompositionOrders_Offline = Value;
                    break;
                case "Offline":
                    setting.Offline = Value;
                    break;
                case "DBAddress_Online":
                    setting.DBAddress_Online = Value;
                    break;
                case "DBAddress_Offline":
                    setting.DBAddress_Offline = Value;
                    break;
                case "Accounts_Offline":
                    setting.Accounts_Offline = Value;
                    break;
                case "DBAddress_Decomposition":
                    setting.DBAddress_Decomposition = Value;
                    break;
                case "DecompositionOrders_Online":
                    setting.DecompositionOrders_Online = Value;
                    break;
                case "AutoInterval":
                    setting.AutoInterval = Value;
                    break;
                case "UploadJobStore_Offline":
                    setting.UploadJobStore_Offline = Value;
                    break;
                case "OrderFlowProgress_Offline":
                    setting.OrderFlowProgress_Offline = Value;
                    break;
                case "ThreadNumber":
                    setting.threadNumber = Value;
                    break;              
                case "DataStore_Offline":
                    setting.DataStore_Offline = Value;
                    break;
                case "ServerName":
                    setting.serverName = Value ;
                    break;
                case "JobLogs_Offline":
                    setting.jobLogs_Offline = Value;
                    break;
                case "RoleJobLevels_Offline":
                    setting.roleJobLevels_Offline = Value;
                    break;
                case "AccountInRole_Offline":
                    setting.accountInRole_Offline = Value;
                    break;
                case "DecompositionDBTimeOut":
                    setting.decompositionDBTimeOut = Value;
                    break;
                case "DropOrderFlag":
                    setting.DropOrderFlag = Value;
                    break;
                default:
                    break;

            }
        }
               
        private string GetProperty(string propertyName)
        {
            string Value = string.Empty;

            switch (propertyName)
            {
                case "Matters_Offline":
                    Value = setting.Matters_Offline;
                    break;
                case "OrderDatas_Offline":
                    Value = setting.OrderDatas_Offline;
                    break;
                case "Distributes_Offline":
                    Value = setting.Distributes_Offline;
                    break;
                case "Jobs_Offline":
                    Value = setting.Jobs_Offline;
                    break;
                case "ParentDatas_Offline":
                    Value = setting.ParentDatas_Offline;
                    break;
                case "ChildDatas_Offline":
                    Value = setting.ChildDatas_Offline;
                    break;
                case "FutureManagement_Offline":
                    Value = setting.FutureManagement_Offline;
                    break;
                case "DecompositionOrders_Offline":
                    Value = setting.DecompositionOrders_Offline;
                    break;
                case "Offline":
                    Value = setting.Offline;
                    break;
                case "DBAddress_Online":
                    Value = setting.DBAddress_Online;
                    break;
                case "DBAddress_Offline":
                    Value = setting.DBAddress_Offline;
                    break;
                case "Accounts_Offline":
                    Value = setting.Accounts_Offline;
                    break;
                case "DBAddress_Decomposition":
                    Value = setting.DBAddress_Decomposition;
                    break;
                case "DecompositionOrders_Online":
                    Value = setting.DecompositionOrders_Online;
                    break;
                case "AutoInterval":
                     Value = setting.AutoInterval ;
                    break;
                case "UploadJobStore_Offline":
                    Value = setting.UploadJobStore_Offline;
                    break;
                case "OrderFlowProgress_Offline":
                    Value = setting.OrderFlowProgress_Offline;
                    break;
                case "ThreadNumber":
                     Value = setting.threadNumber;
                    break;
                case "DataStore_Offline":
                   Value =  setting.DataStore_Offline ;
                    break;
                case "ServerName":
                    Value = setting.serverName ;
                    break;
                case "JobLogs_Offline":
                    Value = setting.jobLogs_Offline ;
                    break;
                case "RoleJobLevels_Offline":
                    Value = setting.roleJobLevels_Offline;
                    break;
                case "AccountInRole_Offline":
                    Value = setting.accountInRole_Offline;
                    break;
                case "DecompositionDBTimeOut":
                    Value = setting.decompositionDBTimeOut;
                    break;
                case "DropOrderFlag":
                    Value = setting.DropOrderFlag;
                    break;
                default:
                    break;
            }

            return Value;

        }

    }
}
